import { Component, Input, OnInit } from '@angular/core';
import { BasicService } from '../../../@core/data/basic.service';
// import { Observable } from 'rxjs/Rx';
// 消息提醒
import { ToasterConfig } from 'angular2-toaster';
import { NotificationsService } from '../../../@core/utils/notifications.service';
const api = 'users';
@Component({
  selector: 'ngx-profile',
  templateUrl: './profile.component.html',
})
export class ProfileComponent implements OnInit {

  user: any;
  config: ToasterConfig;

  constructor(private basicService: BasicService, private notificationsService: NotificationsService) {
    this.config = this.notificationsService.getConfig();
  }
  ngOnInit() {
    this.user = {
      userName: '',
      nickName: '',
      pwd: '',
      email: '',
      phone: '',
      status: '',
    };
    this.getOne();
  }

  getOne() {
    this.basicService.getOne(api + '/1')
      .subscribe((user: any) => {
        this.user = user.row || {};
      });
  }
  save() {
    this.basicService.update(api, this.user).subscribe(
      data => {
        this.getOne();
        this.notificationsService.showToast('success', '操作', '<b>保存 <em>成功！</em></b>');
        return true;
      },
      err => {
        this.notificationsService.showToast('error', '操作', '<b>保存 <em>失败！</em></b>');
        console.error('Error saving!');
        // return Observable.throw(err);
      },
    );
  }
}
